package com.dog.framework.core.utils;


import org.apache.commons.text.RandomStringGenerator;

import static org.apache.commons.text.CharacterPredicates.DIGITS;
import static org.apache.commons.text.CharacterPredicates.LETTERS;

/**
 * 随机字符工具类
 * @author fei.fang
 * @date 2021/4/15
 **/
public class RandomStrUtil {


    private RandomStrUtil() {
    }

    /** 数字和大小写字母 生成器 */
    private static final RandomStringGenerator RANDOM_ALPHANUMERIC_GENERATOR = new RandomStringGenerator.Builder().withinRange('0', 'z').filteredBy(LETTERS, DIGITS).build();

    /** 数字 生成器 */
    private static final RandomStringGenerator RANDOM_NUMERIC_GENERATOR = new RandomStringGenerator.Builder().withinRange('0', '9').build();

    /**
     * 随机 字母(大小写字母)和数字
     * @param length
     * @return
     */
    public static String randomAlphanumeric(Integer length) {
        return RANDOM_ALPHANUMERIC_GENERATOR.generate(length);
    }

    /**
     * 随机 数字
     * @param length
     * @return
     */
    public static String randomNumeric(Integer length) {
        return RANDOM_NUMERIC_GENERATOR.generate(length);
    }


}
